package com.team2.cyber_eye.ActivityHelpers;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.team2.cyber_eye.R;
import com.team2.shared.Direction;

public class AdapterDirections extends BaseAdapter {
    
    private Activity activity;
    private ArrayList<Direction> directions;
    private static LayoutInflater inflater=null;
    
    public AdapterDirections(Activity a, ArrayList<Direction> s)
    {
        activity = a;
        if (s==null)
        	s = new ArrayList<Direction>();
        directions = s;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public int getCount() {
    	if(directions.size()==0) return 1;
        return directions.size();
    }

    public Object getItem(int position) {
    	if (position < 0 || position >= directions.size())
    		return null;
    	
        return directions.get(position);
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.map_directions, null);
        if(directions.isEmpty()) {
        	TextView name=(TextView)vi.findViewById(R.id.direction);
        	name.setText("No directions Found");
        }
        else
        {
            TextView direction=(TextView)vi.findViewById(R.id.direction);
            TextView distance=(TextView)vi.findViewById(R.id.distanceText1);
            
            Direction str = directions.get(position);
            direction.setText(Html.fromHtml(str.getDirectionDesc()));
            distance.setText(str.getDistance()); 
        }
        return vi;
    }
}
